<?php
/**
 * class App_Form_User_Login
 *
 * common user login form
 *
 */
class App_Form_User_Login extends App_Form_Abstract
{
    /**
     * init function - add elements
     *
     * @return object
     */
    public function init()
    {
        $this->setMethod('post');
        $this->setAction('/user/login');
        $this->setAttrib('id', 'form-login');
        $this->addElementPrefixPath('App_Validate',
                                    'App/Validate',
                                    'validate');

        /**
         * email/username
         */
        $this->addElement('text', 'email_username', array(
            'required'   => true,
            'label'      => 'Email: ',
            'filters'    => array('StringTrim'),
            'validators' => array(
                array(
                    'validator' => 'EmailUsername',
                    'breakChainOnFailure' => true,
                ),
                array(
                    'validator' => 'NotEmpty',
                    'breakChainOnFailure' => true,
                ),
            ),
        ));

        /**
         * password
         */
        $this->addElement('password', 'password', array(
            'required'   => true,
            'label'      => 'Password: ',
            'validators' => array(
                array(
                    'validator' => 'StringLength',
                    'options' => array(5, 32, 'messages' => array(
                        Zend_Validate_StringLength::TOO_SHORT => 'Password must be 5-32 characters long',
                        Zend_Validate_StringLength::TOO_LONG => 'Password must be 5-32 characters long'
                    )),
                ),
                array(
                    'validator' => 'NotEmpty',
                    'options' => array('messages' => array(
                        'isEmpty' => "Please provide a password",
                    )),
                    'breakChainOnFailure' => true,
                ),
            ),
        ));

        /**
         * remember me
         */
        $this->addElement('checkbox', 'remember_me', array(
            'required' => false,
            //'label' => 'Keep me logged in',
            'value' => 'on',
            'checked' => 'checked',
        ));

        /**
         * submit
         */
        $this->addElement('submit', 'submit', array(
            'ignore'   => true,
            'label'    => 'login',
        ));

        // And finally add some CSRF protection
        //$this->addElement('hash', 'csrf', array('ignore' => true));
    }

}